/*
 * Copyright (C) 2008,2009,2010,2011  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#ifndef _esymbol_h
#define _esymbol_h

#include "etypes.h"

#define esymbol_p(object)	(etype(object) == t_symbol)

/*
 * Types
 */
struct esymbol {
    esymbol_t	*next;
    eobject_t	 value;
    evector_t	*name;
    eint32_t	 key;
    etag_t	*tag;

    ehash_t	*hash;

    eint32_t	 offset;	/* global table, stack, or record offset */
    eint32_t	 type;		/* packed type or zero */

    eint32_t	 ssa;

    eint32_t	 a_type		: 1;
    eint32_t	 a_token	: 1;
    eint32_t	 a_field	: 1;
    eint32_t	 a_symbol	: 1;
    eint32_t	 a_const	: 1;
    eint32_t	 a_extern	: 1;
    eint32_t	 a_static	: 1;
    eint32_t	 a_global	: 1;
    eint32_t	 a_special	: 1;
    eint32_t	 a_ctor		: 1;
    eint32_t	 a_method	: 1;
    eint32_t	 a_builtin	: 1;
    eint32_t	 a_function	: 1;

    /* temporary generated by optimization */
    eint32_t	 a_expression	: 1;
};

/*
 * Prototypes
 */
extern esymbol_t *
eget_symbol(ehash_t *hash, evector_t *name);

extern esymbol_t *
enew_symbol(ehash_t *hash, evector_t *name);

extern esymbol_t *
echk_bound_symbol(esymbol_t *name);

extern esymbol_t *
eget_bound_symbol(esymbol_t *name);

extern esymbol_t *
enew_bound_symbol(esymbol_t *name);

extern esymbol_t *
enew_temp_symbol(efunction_t *function);

extern void
erem_temp_symbol(efunction_t *function, esymbol_t *symbol);

extern void
init_symbol(void);

#endif /* _esymbol_h */
